package cn.tedu.jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class JDBCLogin {
    public static void main(String[] args) {
        try (Connection connection = DBUtil.getConnection();){
            Statement statement = connection.createStatement();
            Scanner scanner = new Scanner(System.in);
            String username = scanner.nextLine();
            String password = scanner.nextLine();
            String sql = "select nickname from userinfo where username = '" + username + "' and password = '" + password + "'";
            ResultSet resultSet = statement.executeQuery(sql);
            if (resultSet.next()) {
                String nickname = resultSet.getString("nickname");
                System.out.println("登录成功" + nickname);
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
